




var _oMessages =
{
sNoSelectedRelationship: LOCID_RELLST_MUSTSELECT
};





var _oConst =
{

custom:							"custom",
referenced:						"referenced",
referencing:					"referencing",
manyToMany:						"many",
entityId:						"entityId",
relationshipFilter:				"relationshipFilter",

sCreateRelationshipUrlFormat:	"manageRelationship.aspx?entityRole={0}&entityId={1}",
sUpdateRelationshipUrlFormat:	"manageRelationship.aspx?entityRole={0}&entityRelationshipId={1}&entityId={2}",
sUpdateAction:					"update",
sDeleteAction:					"delete",
iRelationshipEditorWidth:		800,
iRelationshipEditorHeight:		600
};





var _sEntityId;





function RelationshipListJsWindowOnLoad()
{

_sEntityId = gridRelationships.GetParameter(_oConst.entityId);


gridRelationships.OnBeforeFormLoad = onRelationshipDblClick;
gridRelationships.SetParameter("disableDblClick", "0");
}
window.attachEvent('onload', RelationshipListJsWindowOnLoad);








function dispatchAction(sRelationshipOid, sAction)
{

if (sRelationshipOid == null)
{
alert(_oMessages.sNoSelectedRelationship);
return;
}

switch (sAction)
{
case _oConst.sDeleteAction:
{
deleteRelationshipAction(sRelationshipOid);
break;
}
case _oConst.sUpdateAction:
{
updateRelationshipAction(sRelationshipOid);
break;
}

}
}



function remoteRelationshipCommandCallback(oResult)
{
if (oResult.Success &&
oResult.RemoteCommand.Command == _oRelUtlConst.sDeleteRelationshipCommand &&
!IsNull(oResult.ReturnValue) &&
oResult.ReturnValue.Used)
{
showUsage(_oSCUConst.sRelationshipMode, oResult.ReturnValue);
}
else
{
gridRelationships.Refresh();
}
return true;
}




function createRelationshipAction(iRole)
{
var role = _oConst.referenced;
if (iRole == 1)
{
role = _oConst.referencing;
}
else if (iRole == 2)
{
role = _oConst.manyToMany;
}

var sUrl = formatString(_oConst.sCreateRelationshipUrlFormat, role, _sEntityId);
openStdWin(sUrl, buildWinName(), _oConst.iRelationshipEditorWidth, _oConst.iRelationshipEditorHeight);
}



function updateRelationshipAction(sRelationshipOid)
{
var sRelationshipId		= getRelationshipId(sRelationshipOid);
var sRelationshipRole	= getEntityRole(sRelationshipOid);
var sUrl				= formatString(_oConst.sUpdateRelationshipUrlFormat, sRelationshipRole, sRelationshipId, _sEntityId);
openStdWin(sUrl, buildWinName(sRelationshipId), _oConst.iRelationshipEditorWidth, _oConst.iRelationshipEditorHeight);
}



function deleteRelationshipAction(sRelationshipOid)
{
var sRelationshipId		= getRelationshipId(sRelationshipOid);
var bCustomRelationship	= (getRelationshipType(sRelationshipOid) == _oConst.custom);
deleteRelationship(sRelationshipId, bCustomRelationship, remoteRelationshipCommandCallback);
}








function onFilterChange()
{
var iTypeFilter			= selTypeFilter.DataValue;


gridRelationships.SetParameter(_oConst.relationshipFilter, (iTypeFilter | _relationshipRole).toString());
gridRelationships.Refresh();
}



function onRelationshipDblClick()
{
updateRelationshipAction(event.ObjectID);
event.returnValue = false;
}












function getSelectedRelationshipOid()
{
var aRecords = gridRelationships.InnerGrid.SelectedRecords;
return (aRecords.length > 0) ? aRecords[0][0] : null;
}



function getRelationshipType(sRelationshipOid)
{
return sRelationshipOid.split(":")[0];
}



function getEntityRole(sRelationshipOid)
{
return sRelationshipOid.split(":")[1];
}



function getRelationshipId(sRelationshipOid)
{
return sRelationshipOid.split(":")[2];
}
